package com.accenture.fd.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.accenture.fd.entity.ClassListEntity;
import com.accenture.fd.entity.SrcType;
import com.accenture.fd.entity.UploadFileForClassListEntity;
import com.accenture.fd.utils.generator.model.ClassToExcelModel;

	@Mapper
	public interface ClassListDao {

		     @Insert("insert into TB00011 value (" + 
		    		 "#{item.screen_id},"+
		    		 "#{item.class_id},"+
		    		 "#{item.class_comment},"+
		    		 "#{item.parent_class},"+
		    		 "#{item.interface_class},"+
		    		 "#{item.name_kanji},"+
		    		 "#{item.name_physics},"+
		    		 "#{item.create_status})")
		     void save(@Param("item")UploadFileForClassListEntity item);
		     
		     @Insert({
		    	 "<script>",
		    	 "insert into TB00011 value ",
		    	 "<foreach collection='classList' item='item' index='index' separator=','>",
		    	 "("+ 
		    	 "#{item.screen_id},"+
	    		 "#{item.class_id},"+
	    		 "#{item.class_comment},"+
	    		 "#{item.parent_class},"+
	    		 "#{item.interface_class},"+
	    		 "#{item.name_kanji},"+
	    		 "#{item.name_physics},"+
	    		 "#{item.create_status})",
		    	 "</foreach>",
		    	 "</script>"
		    	})
		     void saveAll(@Param(value="classList") List<UploadFileForClassListEntity> classList);
		     
		     @Delete("delete from TB00014 ")
		     void delAllClassList();
		     
		     @Insert({
		    	 "<script>",
		    	 "insert into TB00014 value ",
		    	 "<foreach collection='classList' item='item' index='index' separator=','>",
		    	 	"("+ 
		    			 "#{item.seqId},"+
		    			 "#{item.processId},"+
		    		     "#{item.componentType},"+
		    		     "#{item.subPackage},"+
		    		     "#{item.classLogicName},"+
		    		     "#{item.classPhysicsName},"+
		    		     "#{item.comment},"+
		    		     "#{item.typeKubun},"+
		    		     "#{item.type},"+
		    		     "#{item.typeKubunOther},"+
		    		     "#{item.typeOtherSub},"+
		    		     "#{item.saveProject},"+
		    		     "#{item.team})",
		    	 "</foreach>",
		    	 "</script>"
		    	})
		     void saveAllClassList(@Param(value="classList") List<ClassListEntity> classList);

		     @Select(" SELECT screen_id,class_physics_name,class_physics_name,class_logic_name,process_id,m.class_comment,m.sub_package,component_type"+ 
		     		 " FROM (" +
		    		 "  SELECT CONCAT(a.sub_package,'.',a.class_physics_name) as classname, " + 
		    		 "  a.class_physics_name,a.class_logic_name,a.process_id ,a.class_comment,a.sub_package,a.component_type" +
		    		 "  FROM df.tb00014 a " +
		    		 " ) AS m,df.tb00011 b " +
		    		 " WHERE m.classname = b.class_id " +
		    		 " AND m.class_logic_name LIKE concat('%',#{keyword,jdbcType=VARCHAR},'%')" + 
		    		 " GROUP BY screen_id,class_id")
			     @Results({
			    	 @Result(column = "class_physics_name", property ="classId"),
			    	 @Result(column = "sub_package", property ="classPakage"),
			    	 @Result(column = "process_id", property ="processingId"),
			    	 @Result(column = "class_logic_name", property ="classComment"),
			    	 @Result(column = "component_type", property ="classType"),
			     })
			List<SrcType> findByKeyWord(String keyword);
		     
		 	@Select("SELECT class_comment,sub_package,component_type,class_physics_name FROM tb00014 where process_id  = #{screenid} and class_logic_name = #{classid}")
			@Results({ @Result(property = "fieldClassInfo", column = "class_comment"),
					@Result(property = "fieldImplClassNm", column = "sub_package"),
					@Result(property = "fieldInterface", column = "component_type"),
					@Result(property = "fieldClassPhysicsNm", column = "class_physics_name"), })
			ClassToExcelModel getClassDesignModel(@Param("screenid") String screenid, @Param("classid") String designId);
			
	}
